/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI_Busquedas;

import AccesoBusquedas.AB_Clientes;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author joselugb
 */
public class Frm_busq_clientes extends javax.swing.JDialog {
    private  AB_Clientes obj;
    private String objcli;
    /**
     * Creates new form Frm_busq_clientes
     */
    public Frm_busq_clientes(java.awt.Frame parent, boolean modal, String objcli) throws Exception {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        //        
        obj = new AB_Clientes();
         setObjcli(objcli);
         jTableClientes.setModel(obj.TCliente(null, 0));
         jTableClientes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          //evento escuchador
         jTableClientes.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {
            @Override
                    public void valueChanged(ListSelectionEvent event) {
                try {
                    jTableAccion(event);
                } catch (Exception ex) {
                    Logger.getLogger(Frm_busq_clientes.class.getName()).log(Level.SEVERE, null, ex);
                }
                    }
         });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    private void jTableAccion(javax.swing.event.ListSelectionEvent evt) throws Exception {
         int filas = jTableClientes.getSelectedRow();
         this.objcli = jTableClientes.getValueAt(filas, 0).toString();
         setObjcli(this.objcli);
         //cConexion.cerrar();
         dispose();                 
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanelTable = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableClientes = new javax.swing.JTable();
        jPanelOpciones = new javax.swing.JPanel();
        jRadioButtonCedula = new javax.swing.JRadioButton();
        jRadioButtonNombres = new javax.swing.JRadioButton();
        jRadioButtonApellidos = new javax.swing.JRadioButton();
        jLabelImagen = new javax.swing.JLabel();
        jPanelFiltros = new javax.swing.JPanel();
        jLabelCI = new javax.swing.JLabel();
        jTextFieldCedula = new javax.swing.JTextField();
        jLabelEjmCI = new javax.swing.JLabel();
        jLabelNombres = new javax.swing.JLabel();
        jTextFieldNombres = new javax.swing.JTextField();
        jLabelApellidos = new javax.swing.JLabel();
        jTextFieldApellidos = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("BUSQUEDA DEL CLIENTE");

        jTableClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTableClientes);

        javax.swing.GroupLayout jPanelTableLayout = new javax.swing.GroupLayout(jPanelTable);
        jPanelTable.setLayout(jPanelTableLayout);
        jPanelTableLayout.setHorizontalGroup(
            jPanelTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 578, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanelTableLayout.setVerticalGroup(
            jPanelTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanelOpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones de Busqueda", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 18))); // NOI18N

        buttonGroup1.add(jRadioButtonCedula);
        jRadioButtonCedula.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonCedula.setText("CEDULA");
        jRadioButtonCedula.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonCedulaMouseClicked(evt);
            }
        });
        jRadioButtonCedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonCedulaActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButtonNombres);
        jRadioButtonNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonNombres.setText("NOMBRES");
        jRadioButtonNombres.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonNombresMouseClicked(evt);
            }
        });

        buttonGroup1.add(jRadioButtonApellidos);
        jRadioButtonApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonApellidos.setText("APELLIDOS");
        jRadioButtonApellidos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonApellidosMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelOpcionesLayout = new javax.swing.GroupLayout(jPanelOpciones);
        jPanelOpciones.setLayout(jPanelOpcionesLayout);
        jPanelOpcionesLayout.setHorizontalGroup(
            jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcionesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButtonCedula)
                .addGap(52, 52, 52)
                .addComponent(jRadioButtonNombres)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addComponent(jRadioButtonApellidos)
                .addContainerGap())
        );
        jPanelOpcionesLayout.setVerticalGroup(
            jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jRadioButtonCedula)
                .addComponent(jRadioButtonNombres)
                .addComponent(jRadioButtonApellidos))
        );

        jLabelImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/32Nuvola_search_person.png"))); // NOI18N

        jPanelFiltros.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabelCI.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelCI.setText("CEDULA/RUC:");

        jTextFieldCedula.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldCedula.setEnabled(false);
        jTextFieldCedula.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldCedulaCaretUpdate(evt);
            }
        });
        jTextFieldCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldCedulaKeyTyped(evt);
            }
        });

        jLabelEjmCI.setText("Ejm: 1715632458001");

        jLabelNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelNombres.setText("NOMBRES:");

        jTextFieldNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldNombres.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jTextFieldNombres.setEnabled(false);
        jTextFieldNombres.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldNombresCaretUpdate(evt);
            }
        });
        jTextFieldNombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNombresKeyTyped(evt);
            }
        });

        jLabelApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelApellidos.setText("APELLIDOS:");

        jTextFieldApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldApellidos.setEnabled(false);
        jTextFieldApellidos.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextFieldApellidosCaretUpdate(evt);
            }
        });
        jTextFieldApellidos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldApellidosKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanelFiltrosLayout = new javax.swing.GroupLayout(jPanelFiltros);
        jPanelFiltros.setLayout(jPanelFiltrosLayout);
        jPanelFiltrosLayout.setHorizontalGroup(
            jPanelFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFiltrosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelCI)
                    .addComponent(jLabelNombres)
                    .addComponent(jLabelApellidos))
                .addGap(32, 32, 32)
                .addGroup(jPanelFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanelFiltrosLayout.createSequentialGroup()
                        .addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelEjmCI))
                    .addComponent(jTextFieldNombres)
                    .addComponent(jTextFieldApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelFiltrosLayout.setVerticalGroup(
            jPanelFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFiltrosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCI)
                    .addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEjmCI))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNombres)
                    .addComponent(jTextFieldNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelFiltrosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelApellidos)
                    .addComponent(jTextFieldApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelFiltros, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelImagen)
                                .addGap(18, 18, 18)
                                .addComponent(jPanelOpciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(99, 99, 99))
                            .addComponent(jPanelTable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelTable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanelOpciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jLabelImagen)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelFiltros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButtonCedulaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonCedulaMouseClicked
        // TODO add your handling code here: 
        jTextFieldCedula.setEnabled(true);
        jTextFieldNombres.setEnabled(false);
        jTextFieldApellidos.setEnabled(false);

    }//GEN-LAST:event_jRadioButtonCedulaMouseClicked

    private void jRadioButtonNombresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonNombresMouseClicked
        // TODO add your handling code here: 
        jTextFieldCedula.setEnabled(false);
        jTextFieldNombres.setEnabled(true);
        jTextFieldApellidos.setEnabled(false);
    }//GEN-LAST:event_jRadioButtonNombresMouseClicked

    private void jRadioButtonApellidosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonApellidosMouseClicked
        // TODO add your handling code here:
        jTextFieldCedula.setEnabled(false);
        jTextFieldNombres.setEnabled(false);
        jTextFieldApellidos.setEnabled(true);
    }//GEN-LAST:event_jRadioButtonApellidosMouseClicked

    private void jRadioButtonCedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonCedulaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButtonCedulaActionPerformed

    private void jTextFieldCedulaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCedulaKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= '0' && t <= '9')) || jTextFieldCedula.getText().length() > 12) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldCedulaKeyTyped

    private void jTextFieldNombresKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNombresKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= 'A' && t <= 'Z') || (t == ' ') || (t == 'Ñ') || (t == 'é') || (t == 'í') || (t == 'ó') || (t == 'ú') || (t == 'á') || (t == 'ñ') || ((t >= 'a' && t <= 'z'))) || jTextFieldNombres.getText().length() > 50) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldNombresKeyTyped

    private void jTextFieldApellidosKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldApellidosKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= 'A' && t <= 'Z') || (t == ' ') || (t == 'Ñ') || (t == 'é') || (t == 'í') || (t == 'ó') || (t == 'ú') || (t == 'á') || (t == 'ñ') || ((t >= 'a' && t <= 'z'))) || jTextFieldApellidos.getText().length() > 50) {
            evt.setKeyChar('\b');
        }
    }//GEN-LAST:event_jTextFieldApellidosKeyTyped

    private void jTextFieldCedulaCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldCedulaCaretUpdate
        // TODO add your handling code here:
        try{
            jTableClientes.setModel(obj.TCliente(this.jTextFieldCedula.getText().trim().toUpperCase(), 1));
        }catch(Exception ex){}
    }//GEN-LAST:event_jTextFieldCedulaCaretUpdate

    private void jTextFieldNombresCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldNombresCaretUpdate
        // TODO add your handling code here:
        try{
            jTableClientes.setModel(obj.TCliente(this.jTextFieldNombres.getText().trim().toUpperCase(), 2));
        }catch(Exception ex){}
    }//GEN-LAST:event_jTextFieldNombresCaretUpdate

    private void jTextFieldApellidosCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextFieldApellidosCaretUpdate
        // TODO add your handling code here:
        try{
            jTableClientes.setModel(obj.TCliente(this.jTextFieldApellidos.getText().trim().toUpperCase(), 3));
        }catch(Exception ex){}
    }//GEN-LAST:event_jTextFieldApellidosCaretUpdate

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frm_busq_clientes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                try{
                    Frm_busq_clientes dialog = new Frm_busq_clientes(new javax.swing.JFrame(), true, "");
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        @Override
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                }catch(Exception ex){}
                //new Frm_busq_clientes().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabelApellidos;
    private javax.swing.JLabel jLabelCI;
    private javax.swing.JLabel jLabelEjmCI;
    private javax.swing.JLabel jLabelImagen;
    private javax.swing.JLabel jLabelNombres;
    private javax.swing.JPanel jPanelFiltros;
    private javax.swing.JPanel jPanelOpciones;
    private javax.swing.JPanel jPanelTable;
    private javax.swing.JRadioButton jRadioButtonApellidos;
    private javax.swing.JRadioButton jRadioButtonCedula;
    private javax.swing.JRadioButton jRadioButtonNombres;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableClientes;
    private javax.swing.JTextField jTextFieldApellidos;
    private javax.swing.JTextField jTextFieldCedula;
    private javax.swing.JTextField jTextFieldNombres;
    // End of variables declaration//GEN-END:variables
     public String getObjcli() {
        return objcli;
    }

    public void setObjcli(String objcli) {
        this.objcli = objcli;
    }
}
